package biz.ormia.app.deployer.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;

public class Deployer implements EntryPoint
{
	public void onModuleLoad()
	{
		RootPanel rootPanel = RootPanel.get("deploy-webapp");

		MenuBar menuBar = buildMenuBar();
		TabPanel tabPanel = new TabPanel();
		// add the deploy tab panel
		tabPanel.add(buildDeployPanel(), "Deployments");
		tabPanel.selectTab(0);
		rootPanel.add(menuBar);
		rootPanel.add(new HTML("<br>"));
		rootPanel.add(tabPanel);
	}
	private MenuBar buildMenuBar()
	{
		MenuBar menuBar = new MenuBar();
		menuBar.setAutoOpen(true);
		MenuBar deployerMenu = new MenuBar(true);
		MenuBar newMenu = new MenuBar(true);

		newMenu.addItem("Deployment", new Command()
		{
			public void execute()
			{
				Window.alert("Selected the new deployment subcommand; would have visibled the new deployment dialog");
			}
		});
		newMenu.addItem("String Replacement", new Command()
		{
			public void execute()
			{
				Window.alert("Selected the new string replacement subcommand; would have visibled the new string replacement dialog");
			}
		});
		deployerMenu.addItem("Properties...", new Command()
		{
			public void execute()
			{
				Window.alert("Selected the Properties command; would have opened a properties dialog");
			}
		});
		deployerMenu.addItem("New", newMenu);
		menuBar.addItem("Deployer", deployerMenu);
		menuBar.setWidth("100%");
		return menuBar;
	}
	private Panel buildDeployPanel()
	{
		VerticalPanel vPanel = new VerticalPanel();
		vPanel.setWidth("100%");
		// add the Deployment questions first
		HTML deployHeader = new HTML("Required Deployment Information");
		deployHeader.addStyleName("sectionHeader");
		vPanel.add(deployHeader);
		FlexTable table = new FlexTable();
		VerticalPanel qBlock = new VerticalPanel();
		qBlock.addStyleName("sectionBlock");
		table.addStyleName("contentblock");
		table.setBorderWidth(1);
		// for each row add the label and control for the form
		table.setWidget(0, 0, new HTML("Deployment Project"));
		table.setWidget(0, 1, new TextBox());
		table.setWidget(1, 0, new HTML("Deployment Target"));
		table.setWidget(1, 1, new TextBox());
		qBlock.add(table);
		vPanel.add(qBlock);
		return vPanel;
	}
}
